package com.yl.applicationsecurity.controller;

import com.github.pagehelper.PageInfo;
import com.yl.applicationsecurity.pojo.ComponentUnauthorized;
import com.yl.applicationsecurity.pojo.InspectionConfiguration;
import com.yl.applicationsecurity.pojo.Result;
import com.yl.applicationsecurity.service.ComponentUnauthorizedService;
import com.yl.applicationsecurity.service.InspectionConfigurationService;
import com.yl.applicationsecurity.service.ScriptStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author 鹤仙问鹿仙
 * @program: Application-security
 * @description:  组件未授权扫描接口
 * @date 2025-01-22 17:42:17
 */
@RestController
@RequestMapping("/componentUnauthorized")
public class ComponentUnauthorizedController {

    @Autowired
    private ComponentUnauthorizedService componentUnauthorizedService;

    @Autowired
    private ScriptStateService scriptStateService;

    @PostMapping("/list")
    public Result list(String[] nationSelect, ComponentUnauthorized componentUnauthorized, @RequestParam(required = false) Date[] startAndEndDate, @RequestParam(defaultValue = "1", value = "pageNum")Integer pageNum
            , @RequestParam(defaultValue = "10", value = "pageSize")Integer pageSize ){
        PageInfo< ComponentUnauthorized> ComponentUnauthorizedPageInfo = null;

        if(startAndEndDate!=null&&startAndEndDate.length!=2){
            ComponentUnauthorizedPageInfo =  componentUnauthorizedService.findListByComponentUnauthorized(nationSelect,componentUnauthorized,null,null,pageNum,pageSize);
        }else{
            ComponentUnauthorizedPageInfo =  componentUnauthorizedService.findListByComponentUnauthorized(nationSelect,componentUnauthorized,startAndEndDate[0],startAndEndDate[1],pageNum,pageSize);
        }
        return Result.success( ComponentUnauthorizedPageInfo);
    }

    @RequestMapping("/updateStatus")
    public Result updateStatus(HttpServletRequest request, String[]  ids, Integer updateStatus) {


        if(componentUnauthorizedService.updateStatus(  ids, updateStatus)!=0){
            return  Result.success("修改成功");
        }else{
            return  Result.error("修改失败");
        }


    }

    @RequestMapping("/updateNation")
    public Result updateNation(HttpServletRequest request, String[]  ids, String nation1) {


        if(componentUnauthorizedService.updateNation(  ids, nation1)!=0){
            return  Result.success("修改成功");
        }else{
            return  Result.error("修改失败");
        }


    }

    @RequestMapping("/insert")
    public Result updateNation(ComponentUnauthorized componentUnauthorized) {
        scriptStateService.updateDate("组件未授权扫描");
        if(componentUnauthorizedService.insert( componentUnauthorized)!=0){
            return  Result.success("添加成功");
        }else{
            return  Result.error("添加失败");
        }


    }


}

